<?php
header("Content-Type: text/html");
header("charset: utf-8");
include_once("_common.php");


?>
<table width="270" border="0" cellpadding="10" cellspacing="1" bordercolor="D6D6D6" bgcolor="D6D6D6">
            <tr>
              <td bgcolor="#FFFFFF"><table width="245" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><table width="100%" border="0" cellpadding="0" cellspacing="1" bordercolor="858585" bgcolor="858585">
                        <tr>
                          <td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="91%">&nbsp;</td>
                              <td width="9%" align="right">
                              <input type="text" id="loungeStx" name="loungeStx" value="<?=$searchText?>" style="width:205px; padding:0 5px; line-height:18px;border:1;" />
                              </td>
                            </tr>
                          </table></td>
                        </tr>
                      </table></td>
                      <td width="10" align="right">
                      	<a href="javascript:loungeSearch();"><img src="../img/product/lounge_search.gif" width="19" border="0" /></a>
                      </td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td height="20" align="right"><strong>인기순</strong></td>
                </tr>
<?

$SQL =    "SELECT lounge,                     ";
$SQL .= "       (SELECT count(1)            ";
$SQL .= "         FROM g4_write_sellitem b ";
$SQL .= "        WHERE b.wr_10=a.lounge     ";
$SQL .= "       ) +                         ";
$SQL .= "       (SELECT count(1)            ";
$SQL .= "         FROM g4_write_buyitem b   ";
$SQL .= "        WHERE b.wr_10=a.lounge     ";
$SQL .= "       ) cnt                       ";
$SQL .= "  FROM g4_lounge_list a            ";
if ($searchText){
	$SQL .= " WHERE a.lounge like '%".$searchText."%'          ";
}
$SQL .= "ORDER BY cnt desc, a.lounge_id     ";


/*$SQL =    "SELECT wr_10 ,              ";
$SQL .= "       count(1) cnt         ";
$SQL .= "  FROM g4_write_sellitem a ";
if ($searchText){
	$SQL .= " WHERE wr_10 like '%".$searchText."%'          ";
}else {
	$SQL .= " WHERE wr_10 != ''          ";
}
$SQL .= " GROUP BY wr_10             ";
$SQL .= "ORDER BY cnt                ";*/


$result = sql_query($SQL);

for ($i=0; $row=sql_fetch_array($result); $i++){
	echo "<tr><td height=\"20\"><a href=\"javascript:goMySearch('my_lounge','".$row['lounge']."')\">".($i+1).". ".$row['lounge']."</a>(".$row['cnt']."건)</td></tr>";
}
?>
                <tr>
                  <td>&nbsp;</td>
                </tr>
              </table></td>
            </tr>
          </table>